/*
 * Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
 *
 * Author:     fanpengcheng <fanpengcheng_cm@deepin.com>
 *
 * Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H

#include <QWidget>

enum eShapeType {
    e_Ellipse,
    e_Rect,
};

class QPainter;
class SwitchButton : public QWidget
{
    Q_OBJECT

public:
    explicit SwitchButton(QWidget *parent = nullptr);
    ~SwitchButton();

private:
    void initMember();
    void initWidget();

public:
    bool isChecked() const;
    eShapeType shapeType() const;
    int rate() const;

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;

public Q_SLOTS:
    void setShapeType(eShapeType eShape);
    void setChecked(bool check);
    void setRate(int rate);

private Q_SLOTS:
    void slot_updatePos();

protected:
    virtual void paintEvent(QPaintEvent *e);
    virtual void mousePressEvent(QMouseEvent *e);

    void drawBg(QPainter *painter, QColor c);
    void drawBall(QPainter *painter, QColor c);

    void paintShape(QPainter *painter, QRectF rect, eShapeType eShapeType);

private:
    eShapeType m_eShape;
    bool m_checked;
    int m_radius;
    int m_rate;            //rate  1-10
    QPointF m_ballPos;
    QTimer *m_timer;
};

#endif // SWITCHBUTTON_H
